package com.coocaa.optimizer.movie.cleaner.manager;

import android.content.Context;
import android.os.Environment;

import com.coocaa.optimizer.movie.cleaner.config.CleanerConfig;
import com.coocaa.optimizer.movie.cleaner.config.CleanerConfigFactory;

/**
 * Created by lu on 17-3-29.
 */

public class CleanerManagerImpl implements CleanerManager {
    private CleanerConfig config = null;

    CleanerManagerImpl(Context context) {
        config = CleanerConfigFactory.factory.create(context);
    }

    @Override
    public boolean canAutoClean() {
        return config.getAutoClean();
    }

    @Override
    public void setAutoClean(boolean on) {
        config.setAutoClean(on);
    }

    @Override
    public boolean cleanNow() {
        try {
            if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                String path = Environment.getExternalStorageDirectory() + "/iqiyi_p2p/";
                String cmd = "rm -rf " + path;
                Runtime.getRuntime().exec(cmd);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    private static final String MOVIE_PLATFORM = "com.tianci.movieplatform";

    @Override
    public void fixMoviepltform() {
        try {
            String cmd = "pm clear " + MOVIE_PLATFORM;
            Runtime.getRuntime().exec(cmd);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
